import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.net.InetAddress;
import java.net.Socket;
import java.util.ArrayList;

public class Saver extends JFrame implements ActionListener {


    public void actionPerformed(ActionEvent arg0)
    {

        try{


        InetAddress addr = InetAddress.getByName(null);
        Socket socket = new Socket(addr, 8080);

        ObjectOutputStream out = new ObjectOutputStream(new BufferedOutputStream(socket.getOutputStream()));
        out.writeObject(new Exchanger(70,null));
        //  System.out.println("Ok");

        out.flush();  //чудный метод.

        ObjectInputStream in = new ObjectInputStream(new BufferedInputStream(socket.getInputStream()));
        Object object = in.readObject();


            String x = (String)object;

            if(x.equals("0"))
            {
                JOptionPane.showMessageDialog(null,"Список сохранен", "OK",
                        JOptionPane.INFORMATION_MESSAGE);
            }

            else
            {
                JOptionPane.showMessageDialog(null,"Ошибка сохранения", "Error",
                        JOptionPane.ERROR_MESSAGE);
            }
    }


        catch (Exception e)
    {
        System.out.println("init error: " +e); // Print exception

        e.printStackTrace();
    }





}

}
